//
//  OrderPriceListView.m
//  danpin
//
//  Created by chuangjia on 5/11/2015.
//  Copyright © 2015 chuangjia. All rights reserved.
//

#import "OrderPriceListView.h"
#import "viewconfig.h"
#import "NSDictionary+ObjectExt.h"
@interface OrderPriceListView ()<UITableViewDataSource,UITableViewDelegate>
{
    
}
@property(nonatomic,strong)UITableView *tbview;
@end
@implementation OrderPriceListView
@synthesize tbview=_tbview;
@synthesize itemDatas=_itemDatas;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self initUI];
    }
    return self;
}
-(void)setCallBack:(void(^)(UIView *,id,id))callback
{
    self.actionBlock =callback;
}
-(void)keyboardHide
{
    if (self.actionBlock) {
        self.actionBlock(self,nil,nil);
    }
    [self removeFromSuperview];
}
-(void)dealloc
{
    self.actionBlock =nil;
    self.tbview =nil;
    self.itemDatas =nil;
//    NSLog(@"%s", __PRETTY_FUNCTION__);
}
-(void)initUI
{
    _tbview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height) style:UITableViewStylePlain];
    _tbview.delegate = self;
    _tbview.dataSource = self;
    _tbview.backgroundColor =[UIColor whiteColor];
    _tbview.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    _tbview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self addSubview:_tbview];
}
#pragma mark - tableview
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _itemDatas.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return PHOTO_FRAME_WIDTH*7;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = (UITableViewCell*)[tableView  dequeueReusableCellWithIdentifier:@"OrderPriceListViewCell"];
    if(cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"OrderPriceListViewCell"];
        cell.contentView.backgroundColor = [UIColor clearColor];
        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
        cell.selectedBackgroundView.backgroundColor =UIColorFromRGB(0xf4f4f4);
    }
    if (indexPath.row>=_itemDatas.count) {
        return cell;
    }
    NSDictionary *dict = [_itemDatas objectAtIndex:indexPath.row];
    UILabel *title =[[UILabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,PHOTO_FRAME_WIDTH, DEVICE_WIDTH,PHOTO_FRAME_WIDTH*2)];
    title.backgroundColor = [UIColor clearColor];
    title.textColor = CONTEXT_COLOR;
    title.textAlignment = NSTextAlignmentLeft;
    title.font = FONT_BOLD(12);
    title.text =[dict stringForKey:@"title" withDefaultValue:@""];
    [cell addSubview:title];
    title=nil;
    
   
    UILabel *price =[[UILabel alloc] initWithFrame:CGRectMake(DEVICE_WIDTH/2-PHOTO_FRAME_WIDTH,PHOTO_FRAME_WIDTH, DEVICE_WIDTH/2,PHOTO_FRAME_WIDTH*2)];
    price.backgroundColor = [UIColor clearColor];
    price.textColor = CONTEXT_COLOR;
    price.textAlignment = NSTextAlignmentRight;
    price.font = FONT_BOLD(12);
    price.text =[dict stringForKey:@"fee" withDefaultValue:@""];
    [cell addSubview:price];
    price=nil;
    
    UILabel *desc =[[UILabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,PHOTO_FRAME_WIDTH*4, DEVICE_WIDTH,PHOTO_FRAME_WIDTH*2)];
    desc.backgroundColor = [UIColor clearColor];
    desc.textColor = CONTEXT_COLOR;
    desc.textAlignment = NSTextAlignmentLeft;
    desc.font = FONT(12);
    desc.text =[dict stringForKey:@"desc" withDefaultValue:@""];
    [cell addSubview:desc];
    desc=nil;
    
    return cell;
}
@end
